package com.qfedu.config;

import com.qfedu.interceptor.CheckTokenInterceptor;
import com.qfedu.interceptor.SetTimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * Date 2021-9-23
     * 配置请求拦截器
     * @Author Liux8
     * */

    @Autowired
    private CheckTokenInterceptor checkTokenInterceptor; //注入拦截器方法

    @Autowired
    private SetTimeInterceptor setTimeInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 设置拦截条件
        registry.addInterceptor(checkTokenInterceptor)
                .addPathPatterns("/shopcart/**")//指定拦截的接口
                .addPathPatterns("/oreders/**")
               // .excludePathPatterns("/user/**");//指定不会被拦截的接口
                .addPathPatterns("/user/check")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/resgist");
        registry.addInterceptor(setTimeInterceptor).addPathPatterns("/**");
    }
}
